package vip.xiaonuo.sys.modular.courseselection.controller;

import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.response.ErrorResponseData;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.sys.modular.courseselection.dto.CourseSelectionQryDto;
import vip.xiaonuo.sys.modular.courseselection.entity.CourseSelection;
import vip.xiaonuo.sys.modular.courseselection.service.CourseSelectionCheckService;
import vip.xiaonuo.sys.modular.courseselection.service.CourseSelectionService;

import javax.annotation.Resource;

/**
 * @author 墨塵
 * @since 2022/7/20
 */
@RestController
@RequestMapping("/courseSelection/**")
public class CourseSelectionController {

    @Resource
    private CourseSelectionService courseSelectionService;

    @Resource
    private CourseSelectionCheckService courseSelectionCheckService;

    @PostMapping("/getBaseInfo")
    @BusinessLog(title = "选课——基础信息", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getBaseInfo(@RequestBody CourseSelectionQryDto dto) {
        return new SuccessResponseData(courseSelectionService.getBaseInfo(dto));
    }


    @PostMapping("/getCryInfo")
    @BusinessLog(title = "选课——内容信息", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getCryInfo(@RequestBody CourseSelectionQryDto dto) {
        return new SuccessResponseData(courseSelectionService.getCryInfo(dto));
    }

    @PostMapping("/toSelection")
    @BusinessLog(title = "选课——添加信息", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData toSelection(@RequestBody CourseSelection entity) {
        int count = courseSelectionService.toSelection(entity);
        if (count > 0) {
            return new SuccessResponseData();
        } else {
            return new ErrorResponseData(500, "添加选课信息失败");
        }
    }

    @PostMapping("/cancelSelection")
    @BusinessLog(title = "选课——取消选课", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData cancelSelection(@RequestBody CourseSelection entity) {
        int count = courseSelectionService.cancelSelection(entity);
        if (count > 0) {
            return new SuccessResponseData();
        } else {
            return new ErrorResponseData(500, "取消选课失败");
        }
    }

    @PostMapping("/check")
    @BusinessLog(title = "选课——校验", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData check(@RequestBody CourseSelectionQryDto dto) {
        return new SuccessResponseData(courseSelectionCheckService.getResult(dto));
    }

    @PostMapping("/emptySelection")
    @BusinessLog(title = "选课——清空选课", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData emptySelection(@RequestBody CourseSelectionQryDto dto) {
        int count = courseSelectionService.emptySelection(dto);
        if (count > 0) {
            return new SuccessResponseData();
        } else {
            return new ErrorResponseData(500, "清空选课失败");
        }
    }


    @PostMapping("/getCsDetailList")
    @BusinessLog(title = "选课——选课详情", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getCsDetailList(@RequestBody CourseSelectionQryDto dto) {
        return new SuccessResponseData(courseSelectionService.getCsDetailList(dto));
    }

    @PostMapping("/exportCsDetailList")
    @BusinessLog(title = "选课-导出选课详情", opType = LogAnnotionOpTypeEnum.EXPORT)
    public void exportCsDetailList(@RequestBody CourseSelectionQryDto dto) {
        courseSelectionService.exportCsDetailList(dto);
    }
    /**
     * 下载学生采集模板
     *
     * @author kongxm
     * @date 2022-07-07 21:52:25
     */

    @GetMapping("/exportSelection")
    @BusinessLog(title = "选课-导出课表", opType = LogAnnotionOpTypeEnum.EXPORT)
    public void exportSelection(CourseSelectionQryDto dto) {
        courseSelectionService.exportSelection(dto);
    }

    @PostMapping("/getCsStuList")
    @BusinessLog(title = "选课——学生选课列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getCsStuList(@RequestBody CourseSelectionQryDto dto) {
        return new SuccessResponseData(courseSelectionService.getStuList(dto));
    }

    @PostMapping("/getCpStuList")
    @BusinessLog(title = "开课——学生列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getCpStuList(@RequestBody CourseSelectionQryDto dto) {
        return new SuccessResponseData(courseSelectionService.getStuAllList(dto));
    }
}
